package ptumall.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ptumall.dao.HistoryKeywordDao;

import java.util.List;

@Service
public class HistoryKeywordService {

    @Autowired
    private HistoryKeywordDao historyKeywordDao;

    public List<String> getHistory(Long userId, int size) {
        return historyKeywordDao.selectHistory(userId, size);
    }

    @Transactional
    public void saveHistory(Long userId, String keyword) {
        historyKeywordDao.insertOrUpdate(userId, keyword);
    }

    public void deleteHistory(Long userId, String keyword) {
        historyKeywordDao.delete(userId, keyword);
    }

    public void clearHistory(Long userId) {
        historyKeywordDao.deleteAll(userId);
    }
}
